﻿@model MvcApplication6.Models.AddProductModel

@{
    ViewBag.Title = "AddProduct_2";
}

<script src="../../Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="../../Scripts/calendar.js" type="text/javascript"></script>
<script src="../../Content/includes/ckeditor/ckeditor.js" type="text/javascript"></script>
<link href="../../Content/includes/ckeditor/contents.css" rel="stylesheet" type="text/css"/>
<link href="../../Content/css/nn-styles.css" rel="stylesheet" type="text/css"/>

@{
    if (@ViewBag.error == "OK")
    {
      <script type="text/javascript">
          alert("Successfull !!! ..... ");
      </script>
    }
    else
    {
        if (ViewBag.error == "NOT")
        {
          <script type="text/javascript">
              alert("Error !!! ..... ");
          </script>
        }
    }
}

<div>
    <a style="margin-left:127px;margin-top:5px;" href="http://aptechpro.vn/"><b>Trang chủ</b></a>    
    <h1 class="ad-title"><center>Add Product</center></h1>

     @using (Html.BeginForm("AddProduct", "Admin", FormMethod.Post, new { id = "add_news", name = "add_news", enctype = "multipart/form-data" }))
     {       
        @Html.AntiForgeryToken() <!--Chống giả lập yêu cầu -->
        @Html.ValidationSummary(true) <!-- hiện thị kiểm lỗi phía Server-->   

        <p>
            <label for="menu1"><b>Menu 1:</b></label>
            @Html.TextBox("MenuName1", null, new { disabled = "true", style = "width:300px"})
            @Html.HiddenFor(model => model.modelController.IdL1)
        </p>
        <p>
            <label for="menu2"><b>Menu 2:</b></label>
            @Html.TextBox("MenuName2", null, new { disabled = "true", style = "width:300px" })
            @Html.HiddenFor(model => model.modelController.IdL2)
        </p>
        <p>
            <label for="menu2"><b>Menu 3:</b></label>
            @Html.TextBox("MenuName3", null, new { disabled = "true", style = "width:300px" })
            @Html.HiddenFor(model => model.modelController.IdL3)
        </p>
        <p>
            @Html.TextBoxFor(model => model.modelController.Id, new { style = "display: none;" })
        </p>         
        <p>
            <label for="position1"><b>Vị trí 1:</b></label>
            @Html.TextBoxFor(model => model.modelController.Position1, new { name = "position1", id = "position1", type = "number", style = "width:294px" })
            @Html.ValidationMessageFor(model => model.modelController.Position1)
        </p>
        <p>
            <label for="position2"><b>Vị trí 2:</b></label>
            @Html.TextBoxFor(model => model.modelController.Position2, new { name = "position2", id = "position2", type = "number", style = "width:294px" })
            @Html.ValidationMessageFor(model => model.modelController.Position2)
        </p> 
        <p>
            <label for="position3"><b>Vị trí 3:</b></label>
            @Html.TextBoxFor(model => model.modelController.Position3, new { name = "position3", id = "position3", type = "number", style = "width:294px" })
            @Html.ValidationMessageFor(model => model.modelController.Position3)
        </p>
        <p>
            <label for="position4"><b>Vị trí 4:</b></label>
            @Html.TextBoxFor(model => model.modelController.Position4, new { name = "position4", id = "position4", type = "number", style = "width:294px" })
            @Html.ValidationMessageFor(model => model.modelController.Position4)
        </p>
        <p>
            <label for="position5"><b>Vị trí 5:</b></label>
            @Html.TextBoxFor(model => model.modelController.Position5, new { name = "position5", id = "position5", type = "number", style = "width:294px" })
            @Html.ValidationMessageFor(model => model.modelController.Position5)
        </p> 
        <p>
            <label for="position6"><b>Vị trí 6:</b></label>
            @Html.TextBoxFor(model => model.modelController.Position6, new { name = "position6", id = "position6", type = "number", style = "width:294px" })
            @Html.ValidationMessageFor(model => model.modelController.Position6)
        </p>
        <p>
            <label for="new_product"><b>Là sản phẩm mới:</b></label>
            @Html.CheckBoxFor(model => model.modelController.checkbox_NewproFlag) 
        </p>       
        <p>
            <label for="sale_product"><b>Sản phẩm sales:</b></label>
            @Html.CheckBoxFor(model => model.modelController.checkbox_ProsalesFlag)
        </p>
        <p>
            <label for="sale_product"><b>Sản phẩm bán chạy</b></label>
            @Html.CheckBoxFor(model => model.modelController.checkbox_ProsaleFlag)   
        </p>                     
        <p>
            <label for="Product"><b>Tên sản phẩm:</b></label>
            @Html.TextBoxFor(model => model.modelController.Name, new { name = "nameProduct", id = "nameProduct", type = "text", style = "width:294px", maxlength = "100" })
            @Html.ValidationMessageFor(model => model.modelController.Name)        
        </p>   
        <p>
            <label for="Product"><b>Tiêu đề sản phẩm:</b></label>
            @Html.TextAreaFor(model => model.modelController.title, new { name = "titleProduct", id = "titleProduct", type = "text", style = "width:294px", maxlength = "100" })
            @Html.ValidationMessageFor(model => model.modelController.title)        
        </p> 
        <p>
            <label for="ckeditor"><b>Tổng quan sản phẩm:</b></label>
            @Html.TextAreaFor(model => model.modelController.introduce_pro, new { cols = "80", id = "editor_tongquan", name = "editor_tongquan", rows = "10" })
            <script type="text/javascript">
                CKEDITOR.replace('editor_tongquan');
            </script>
        </p>                            
        <p>
            <label for="Bhanh"><b>Bảo hành:</b></label>
            @Html.TextBoxFor(model => model.modelController.Warranty, new { name = "nameBhanh", id = "nameBhanh", type = "text", style = "width:294px", maxlength = "100" })
            @Html.ValidationMessageFor(model => model.modelController.Warranty) 
        </p>
        <p>
            <label for="Xsu"><b>Xuất xứ:</b></label>
            @Html.TextBoxFor(model => model.modelController.MakeIn, new { name = "nameXsu", id = "nameXsu", type = "text", style = "width:294px", maxlength = "100" })
            @Html.ValidationMessageFor(model => model.modelController.MakeIn) 
        </p>
        <p>
            <label for="Price"><b>Giá:</b></label>
            @Html.TextBoxFor(model => model.moneyAo, new { name = "currency", id = "number", type = "text", style = "width:294px", pattern = "[0-9]*", Value = Model.modelController.Price })
            @Html.ValidationMessageFor(model => model.moneyAo)
            <br />
            @Html.TextBoxFor(model => model.modelController.Price, new { name = "namePrice", id = "display", type = "number", style = "display: none;", maxlength = "100" })
            @Html.ValidationMessageFor(model => model.modelController.Price)
        </p>
        <p>
            <label for="Sale"><b>Giảm giá:</b></label>
            @Html.TextBoxFor(model => model.modelController.Sale, new { name = "nameSale", id = "nameSale", type = "number", style = "width:294px", maxlength = "100" })
            @Html.ValidationMessageFor(model => model.modelController.Sale)
        </p> 
        <p>
            <label for="Sale"><b>Call giá sỉ:</b></label>
            @Html.TextBoxFor(model => model.modelController.CallToSale, new { name = "CallToSale", id = "CallToSale", type = "text", style = "width:294px", maxlength = "25" })
            @*@Html.ValidationMessageFor(model => model.modelController.Sale)*@
        </p>          
        <p>
            <label for="image"><b>Image: </b></label>
            @Html.TextBoxFor(model => model.modelController.FileImage, new { name = "title", type = "file", id = "image", style = "width:350px;", maxlength = "200", onchange = "ImageClick()" })
            <div class="div_image" style = "padding-left:294px">
                <img class="image_show" id="show_image" src="../../Upload/Images/@Model.modelController.Image" style="width: 150px; height: 200px;">
                @Html.TextBoxFor(model => model.modelController.Image, new { id = "name_image", style = "display: none;" })
            </div>	
        </p>          
        <p>
            <label for="ckeditor"><b>Nội dung: </b></label>
            @Html.TextAreaFor(model => model.modelController.InfPro, new { cols = "80", id = "editor", name = "editor", rows = "10" })
            <script type="text/javascript">
                CKEDITOR.replace('editor');
            </script>
        </p>
        <div class="btn-submit">
        @{
         if (@ViewBag.Button == "Edit")
         {
                <input type="submit" name="Command" class="btn_contact" value="Edit" />
         }
         else
         {
                <input type="submit" name="Command" class="btn_contact" value="Create" />
         }            
        }
        </div>
     }
</div><!-- end.content-->

<!--oooooooooooooooooooooooooooooooooooKiem tra anhoooooooooooooooooooooooooooooooooooooooooooooooo -->
<script type='text/javascript'>
    function ImageClick() {
        //When the form is submitted
        //$('form').submit(function (e) {
        //Check that a file exists and that it is of the appropriate extension
        var fileInput = document.getElementById("image");
        var file = fileInput.files[0];

        if (file.name.length > 20) {
            $("#image").val(""); //Gia tri ke chu choose
            $("#show_image").attr("src", "../../Upload/Images/"); //Khung hinh hien thi
            alert("Tên ảnh upload phải nhỏ hơn 20 từ");
        }
        else {
            if (!isValidImage($("#image").val())) {
                //e.preventDefault();
                $("#image").val("");
                $("#show_image").attr("src", "../../Upload/Images/");
                alert("Chọn file ảnh hợp lệ !!! . (.jpg. png .jpeg....)");
            }
            else {
                $("#show_image").attr("src", "../../Upload/Images/" + $("#image").val().replace(/^.*\\/, "")).width(150).height(200);
                $("#name_image").text($("#image").val().replace(/^.*\\/, ""));
            }
        }
    }

    //Helper method to get the file name
    function getExtension(filename) {
        var parts = filename.split('.');
        return parts[parts.length - 1];
    }
    //Helper function to determine if the file type is valid
    function isValidImage(filename) {
        var ext = getExtension(filename);
        switch (ext.toLowerCase()) {
            case 'jpg':
            case 'jpeg':
            case 'gif':
            case 'bmp':
            case 'png':
                //It is an image - allow it
                return true;
        }
        //It wasn't a valid extension - don't submit the form
        return false;
    }

    //Format Gia tien
    document.getElementById("number").onblur = function () {
        this.value = parseFloat(this.value.replace(/,/g, ""))
                    .toString()
                    .replace(/\B(?=(\d{3})+(?!\d))/g, ",");

        if (this.value == "NaN") {
            this.value = 0;
        }
        document.getElementById("display").value = this.value.replace(/,/g, "")

    }
</script>


